package tp.pr4;

import java.util.ArrayList;

public class Map
{

	private ArrayList<Door> mapa = new ArrayList<Door>();
	private Room currentRoom;

	// constructor
	public Map(Room initRoom)
	{
		this.mapa = new ArrayList<Door>();
		currentRoom=initRoom;
	}

	//De game, referente a room
	
	public Room getCurrentRoom()
	{
		return this.currentRoom;
	}
	
	public void setCurrentRoom(Room currentRoom)
	{
		this.currentRoom=currentRoom;
	}
	
	// metodos
	
	public void addDoor(Door d)
	{
		mapa.add(d);
	}
	public Door addDoor(Room source, Directions direction, Room target) // puerta normal
	{
		Door puerta = new Door(source, direction, target, false);
		mapa.add(puerta);
		return puerta;
	}

	public Door addBidirectionalDoor(Room source, Directions direction,
			Room target) // puerta bidireccional
	{
		Door puerta = new Door(source, direction, target, true);
		mapa.add(puerta);
		return puerta;
	}

	public Door getDoor(Room room, Directions dir) //funciona, pero no se porque funciona de esta forma tan cutre
															
	{
		Door puerta = null;
		Door aux = puerta;
		int i = 0;

		while (i < this.mapa.size())
		{
			aux=mapa.get(i);
			if (aux.getOrigen()==room && aux.getDir()==dir) 
			{
				puerta= aux; //antes era return
			}
			
			if(aux.getDestino()==room && aux.getDir().getOpuesto()==dir)
			{
				puerta= aux;//antes era return
			}
			i++;
		}

		return puerta;
	}
	public Door getDoor(Door d) {
		for (int i=0;i<this.mapa.size();i++) {
			if (d.equals(this.mapa.get(i))) {
				return this.mapa.get(i);
			}
		}
		return null;
			
	}
}
